process.env.NODE_ENV = 'production';
const koa = require('koa');
const app = new koa();
const debug = require('debug')('kinohana-server')
const response = require('./middleware/response');
const yusupApi = require('./middleware/yusupApi');
const bodyParser = require('koa-bodyparser')
const config = require('./config')
const cors = require('koa2-cors');
const Cache = require('node-cache');
global.cache = new Cache({ checkperiod: 7200 });
const { initAccessToken } = require('./libs/util')
const {
    initWechatApi
} = require('./tools/wechatApi');

// const coWechat = require('./tools/coWechat');
initAccessToken(config.wConfig);
// initWechatApi();
// let wechat = require('./wechat/g.js');
// const {
//     wConfig
// } = require('./config');
// app.use(wechat(wConfig));
//app.use(coWechat)
// 使用响应处理中间件
app.use(yusupApi)
app.use(response)
// 处理跨域中间件
app.use(cors());
// 解析请求体
app.use(bodyParser({
    enableTypes: ['json', 'form', 'text'],
    extendTypes: {
        text: ['text/xml', 'application/xml']
    }
}));
// 引入路由分发
const router = require('./routes')
app.use(router.routes());


// 启动程序，监听端口
app.listen(config.port, () => debug(`listening on port http://${config.ip}:${config.port}`))